//
//  SFCEmptyRepoTests.m
//  SVNForCocoa
//
//  Created by Jeremy Pereira on 11/11/2013.
//  Copyright (c) 2013 Jeremy Pereira. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "SFCLib+Internals.h"
#import "SFCClient.h"
#import "SFCFileSetUpHelper.h"
#import "SFCTestAuthProvider.h"


@interface SFCEmptyRepoTests : XCTestCase

@end

@implementation SFCEmptyRepoTests
{
	SFCFileSetUpHelper* fileHelper;
}


- (void)setUp
{
    [super setUp];
    if (fileHelper == nil)
    {
        fileHelper = [[SFCFileSetUpHelper alloc] initWithFolder: [self className]];
    }
    [fileHelper resetFiles];
}


- (void)tearDown
{
    // Put teardown code here. This method is called after the invocation of
    // each test method in the class.
    [super tearDown];
}

/*
 *  Test that we can checkout a directory from a file URL
 */
-(void) testCheckout
{
    NSURL* repoUrl = [fileHelper repoURI];
    NSError* error = nil;
	SFCClient* client = [[SFCClient alloc] initWithError: &error];
    SFCTestUserNameProvider* userNameProvider = [[SFCTestUserNameProvider alloc] init];

    if (client == nil)
    {
        XCTFail(@"Failed to create client context, %@", error);
    }
    else
    {
        [client addAuthenticationProvider: userNameProvider];
        SFCRevNum revNum = -1;
        bool success = [client checkoutURL: repoUrl
                                      path: [fileHelper wcPath]
                               pegRevision: nil
                                  revision: nil
                                     depth: SFC_DEPTH_INFINITY
                           ignoreExternals: false
              allowUnversionedObstructions: false
                            resultRevision: &revNum
                                     error: &error];
        if (!success)
        {
            XCTFail(@"Checkout failed, error %@", error);
        }
        else
        {
            NSFileManager* fm = [NSFileManager defaultManager];
            XCTAssertTrue(revNum > -1, @"Revnum was not filled in");
            BOOL isDirectory = NO;
            bool exists = [fm fileExistsAtPath: [fileHelper wcPath] isDirectory: &isDirectory];
            XCTAssertTrue(exists && isDirectory, @"%@ was not created", [fileHelper wcPath]);
            NSString* svnDir = [[fileHelper wcPath] stringByAppendingPathComponent: @".svn"];
            exists = [fm fileExistsAtPath: svnDir isDirectory: &isDirectory];
        	XCTAssertTrue(exists && isDirectory, @"%@ was not created", svnDir);
        }
    }
}

#pragma

@end
